//
//  ActivityTableViewCell.m
//  UI12豆瓣大项目
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ActivityTableViewCell.h"
#import "AppTools.h"
#import "UIImageView+WebCache.h"
@implementation ActivityTableViewCell
- (void)dealloc
{
    [_activity release];
    [_addressImageView release];
    [_addressLabel release];
    [_bgImageView release];
    [_timeImageView release];
    [_contentImageView release];
    [_stypeImageView release];
    [_stypeLabel release];
    [_pictureImageView release];
    [_wisherLabel release];
    [_joinLabel release];
    [_timeImageView release];
    [_timeLabel release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        
        
        self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake((375 - 350)/2, 10, 350, 140)];
        self.bgImageView.image = [UIImage imageNamed:@"bg_eventlistcell@2x"];
        [self.contentView addSubview:self.bgImageView];
        
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 4, 320, 23)];
        self.titleLabel.text = @"题目:";
        self.titleLabel.font = [UIFont systemFontOfSize:13];
        [self.bgImageView addSubview:self.titleLabel];
        
        
        self.contentImageView = [[UIImageView alloc] initWithFrame:CGRectMake((350 - 335)/2, 28, 335, 108)];
        self.contentImageView.image = [UIImage imageNamed:@"bg_share_large@2x"];
        [self.bgImageView addSubview:self.contentImageView];
        
        
        self.timeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 15, 15)];
        self.timeImageView.image = [UIImage imageNamed:@"icon_date@2x"];
        [self.contentImageView addSubview:self.timeImageView];
        
        
        self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, 1, 200, 21)];
//        self.timeLabel.backgroundColor = [UIColor blackColor];
        self.timeLabel.font = [UIFont systemFontOfSize:13];
        self.timeLabel.text = @"时间:";
        [self.contentImageView addSubview:self.timeLabel];
        
        self.addressImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 25, 15, 15)];
        self.addressImageView.image = [UIImage imageNamed:@"icon_spot@2x"];
        [self.contentImageView addSubview:self.addressImageView];
        
        self.addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, 22, 200, 21)];
//        self.addressLabel.backgroundColor = [UIColor purpleColor];
        self.addressLabel.font = [UIFont systemFontOfSize:13];
        self.addressLabel.text = @"地址:";
        [self.contentImageView addSubview:self.addressLabel];
        
        
        self.stypeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 45, 15, 15)];
        self.stypeImageView.image = [UIImage imageNamed:@"icon_catalog@2x"];
        [self.contentImageView addSubview:self.stypeImageView];
        
        
        self.stypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, 43, 200, 21)];
//        self.stypeLabel.backgroundColor = [UIColor yellowColor];
        self.stypeLabel.font = [UIFont systemFontOfSize:13];
        self.stypeLabel.text = @"类型:";
        [self.contentImageView addSubview:self.stypeLabel];
        
        
        self.pictureImageView = [[UIImageView alloc] initWithFrame:CGRectMake(250, 2, 80, 101)];
        self.pictureImageView.image = [UIImage imageNamed:@"picholder@2x"];
        [self.contentImageView addSubview:self.pictureImageView];
        
        
        self.wisherLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 70, 110, 20)];
//        self.wisherLabel.backgroundColor = [UIColor redColor];
        self.wisherLabel.font = [UIFont systemFontOfSize:13];
        self.wisherLabel.text = @"感兴趣:";
        [self.contentImageView addSubview:self.wisherLabel];
        
        
        self.joinLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 70, 110, 20)];
//        self.joinLabel.backgroundColor = [UIColor blueColor];
        self.joinLabel.font = [UIFont systemFontOfSize:13];
        self.joinLabel.text = @"加入:";
        [self.contentImageView addSubview:self.joinLabel];
        
        
        [_addressImageView release];
        [_addressLabel release];
        [_bgImageView release];
        [_timeImageView release];
        [_contentImageView release];
        [_stypeImageView release];
        [_stypeLabel release];
        [_pictureImageView release];
        [_wisherLabel release];
        [_joinLabel release];
        [_timeImageView release];
        [_timeLabel release];
        
    }
    return  self;
}



-(void)setActivity:(Activity *)activity{
    if (_activity != activity) {
        [_activity release];
        _activity = [activity retain];
    }
    self.titleLabel.text = self.activity.title;
//    NSLog(@"sel%@",self.titleLabel.text);
    NSString *a = [self.activity.begin_time substringWithRange:NSMakeRange(5, 11)];
    NSString *b = [self.activity.end_time substringWithRange:NSMakeRange(5, 11)];
    NSString *time = [NSString stringWithFormat:@"%@--%@", a, b];
    self.timeLabel.text = time;
    NSString *stype = [NSString stringWithFormat:@"类型:%@",self.activity.category_name];
    self.stypeLabel.text = stype;
    NSString *address = [NSString stringWithFormat:@"%@",self.activity.address];
    self.addressLabel.text = address;
    NSString *join = [NSString stringWithFormat:@"加入:%ld", self.activity.participant_count];
    self.joinLabel.textColor = [UIColor redColor];
    self.joinLabel.text = join;
    NSString *wisher = [NSString stringWithFormat:@"感兴趣:%ld",self.activity.wisher_count];
    self.wisherLabel.textColor = [UIColor redColor];
    self.wisherLabel.text = wisher;
    

//    [AppTools getImage:self.activity.image block:^(id result) {
//        self.pictureImageView.image = [UIImage imageWithData:result];
//        }];
    
    //第三方有缓存  #import "UIImageView+WebCache.h"
    NSURL *url = [NSURL URLWithString:self.activity.image];
    [self.pictureImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeHoderImage"]];
    
}



@end
